//
//  RZQCuriousSayViewController.m
//  LastOne
//
//  Created by dllo on 15/11/6.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "RZQCuriousSayViewController.h"
#import "FitHeader.h"
#import "HTTPMethod.h"
#import "SayModel.h"
#import "RZQCuriousSayCollectionCell.h"
#import <UIImageView+WebCache.h>
#import "NightHeader.h"
#import "GiFHUD.h"
@interface RZQCuriousSayViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIScrollViewDelegate>
@property(nonatomic, strong)UICollectionView *collectionView;
@property(nonatomic, strong)NSMutableArray *dataSource;
@property(nonatomic, strong)UIImageView *image;

@end

@implementation RZQCuriousSayViewController
#pragma mark 网络请求
-(void)getNet
{
    [GiFHUD show];
    [HTTPMethod getDataByString:[NSString stringWithFormat:@"http://app.qdaily.com/app/options/index/%ld/0.json", _modelData.iD] BodyDic:nil WithDataBlock:^(id data) {
        NSDictionary *dic  = [data objectForKey:@"response"];
        
        NSDictionary *Dic = [dic objectForKey:@"options"];
        NSArray *array = [Dic objectForKey:@"list"];
        for (NSDictionary *dic in array) {
            SayModel *model = [[SayModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [_dataSource addObject:model];
            
        }
        [_collectionView reloadData];
        
 
        [GiFHUD dismiss];
        
    }];
    
}
- (void)viewDidLoad {
  
    [super viewDidLoad];
    
    _dataSource = [NSMutableArray array];
    [self getNet];
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(170 * FitWidth, 250 * FitHeight);
    flowLayout.minimumLineSpacing = 5 * FitWidth;
    flowLayout.sectionInset = UIEdgeInsetsMake(15 * FitHeight, 10 * FitWidth, 10 * FitHeight, 10 * FitWidth);
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 113 * FitHeight) collectionViewLayout:flowLayout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.contentInset = UIEdgeInsetsMake(200 * FitHeight, 0, 0, 0);
    _collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_collectionView];
        
    [_collectionView NightWithType:UIViewColorTypeNormal];
    
        
    [_collectionView registerClass:[RZQCuriousSayCollectionCell
                                    class] forCellWithReuseIdentifier:@"say"];
    
        _image = [[UIImageView alloc]initWithFrame:CGRectMake(0, -200 * FitHeight, ScreenWidth, 200 * FitHeight)];
       [_image sd_setImageWithURL:[NSURL URLWithString:_modelData.image]];
        _image.backgroundColor = [UIColor redColor];
        _image.contentMode = UIViewContentModeScaleAspectFill;
        
        [_collectionView addSubview:_image];
        
        
    [GiFHUD setGifWithImageName:@"loading.gif"];
    


    // Do any additional setup after loading the view.
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat y = scrollView.contentOffset.y -  0 *FitHeight;
    
    if (y <= -200 * FitHeight) {
        CGRect  frame = _image.frame;
        frame.origin.y = y;
        frame.size.height = -y;
        _image.frame = frame;
    }
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    RZQCuriousSayCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"say" forIndexPath:indexPath];
    
    
    cell.modelData = _dataSource[indexPath.row];
    
    
    
    return cell;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return _dataSource.count;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
